package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.DB;
public class ZhuceActivity extends AppCompatActivity {

    private Button text_bt;
    private String nameStr;
    private String passwordStr;
    private EditText yh_et;
    private EditText pwd_et;
    private EditText pwdd_et;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhuce);
        initView();
        initData();
        initEvent();
    }
    private void initView(){
        text_bt = findViewById(R.id.text_bt);
        yh_et = findViewById(R.id.yh_et);
        pwd_et = findViewById(R.id.pwd_et);
        pwdd_et = findViewById(R.id.pwdd_et);
    }
    private void initData(){
        nameStr = yh_et.getText().toString() + "";
        passwordStr = pwd_et.getText().toString() + "";
    }
    private void initEvent(){
text_bt.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        initData();
        if (yh_et.getText().toString().length() >= 3) {
            if (yh_et.getText().toString().length() > 5 && pwd_et.getText().toString().length() <= 15) {
                if (pwdd_et.getText().toString().length() == pwd_et.getText().toString().length()) {
                    Toast.makeText(ZhuceActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(ZhuceActivity.this, MainActivity.class);
                    startActivity(intent);
                } else {
                    Toast.makeText(ZhuceActivity.this, "两次密码不一样", Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(ZhuceActivity.this, "密码格式不符合要求", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(ZhuceActivity.this, "手机号码不符合要求", Toast.LENGTH_SHORT).show();
        }
        DB db = new DB(ZhuceActivity.this);
        db.signInInsert(nameStr, passwordStr);

    }
});
    }

}
